﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Windows;

namespace Refract.Tests
{
    public class TestComponent : Component
    {

    }

    [TestClass]
    public class ComponentFixture
    {
        private TestComponent _TestComponent;
        [TestInitialize]
        public void Initialize()
        {
            _TestComponent = new TestComponent();
        }

        [TestMethod]
        public void TestComponent_created()
        {
            Assert.IsNotNull(_TestComponent, "_TestComponent is null.");
        }

        [TestMethod]
        public void TestComponent_sets_correct_dispatcher()
        {
            Assert.AreEqual(_TestComponent.Dispatcher, Deployment.Current.Dispatcher);
        }

        [TestMethod]
        public void TestComponent_is_not_in_design_mode()
        {
            Assert.IsFalse(_TestComponent.IsDesignMode, "_TestComponent thinks its in design mode.");
        }

        [TestMethod]
        public void TestComponent_raises_property_change_notification_event()
        {
            //todo: Need to test both paths: with dispatcher and without
            bool raised = false;
            string changedPropertyName = string.Empty;

            _TestComponent.PropertyChanged+=new System.ComponentModel.PropertyChangedEventHandler(
                (s, e) => { raised = true; changedPropertyName = e.PropertyName; });

            const string TestPropertyName = "TestProperty";
            _TestComponent.RaisePropertyChanged(TestPropertyName);

            Assert.IsTrue(raised, "Event not raised.");
            Assert.AreEqual(TestPropertyName, changedPropertyName);

            
        }

    }
}